<template>
	<view class="page">
		<!-- 搜索栏 -->
		<view class="page-block search-bar-block">
			<view class="search-bar-wapper">
				<image class="search-icon" src="../../static/icos/search.png" mode=""></image>
				<input class="search-input" maxlength="10" @confirm="searchTrailer" confirm-type="search" type="text" value="" placeholder="找预告" />	
			</view>				
		</view>
		
		<!-- 电影列表 -->
		<view class="movie-list-block page-block">
			<view class="movie-wapper" v-for="trailer in trailerList">
				<image @click="showTrailer" :data-trailerid="trailer.id" class="movie-image" :src="trailer.cover" mode=""></image>
			</view>
			<!-- <view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view>
			<view class="movie-wapper">
				<image class="movie-image" src="../../static/poster/civilwar.jpg" mode=""></image>
			</view> -->
		</view>
	</view>	
</template>

<script>
	export default {
		data() {
			return {
				trailerList:[],
				keywords:'',
				page:1, //当前页
				totalPages:1 //总页数
			}
		},
		onLoad() {
			var me=this;
			var serverUrl=this.$serverUrl;
			
			uni.showLoading({
				mask:true,
				title:"请稍后..."
			});
			uni.showNavigationBarLoading()
			
			//查询猜你喜欢
			uni.request({			
				url: serverUrl+'/search/list?keywords=&page=&pageSize=',
				method: 'GET',
				data: {},
				success: res => {
					// debugger
					// console.log(res.data)
					if (res.data.status == 200) {
						
						var trailerList = res.data.data.rows;
						me.trailerList = trailerList;
					}
			
				},
				fail: () => {},
				complete: () => {
					uni.hideLoading();
					uni.hideNavigationBarLoading()
				}
			});
		},
		onReachBottom() {
			var me=this;
			var page=this.page+1;
			var keywords=me.keywords
			var totalPages=me.totalPages;
			
			if(page>totalPages){
				return;
			}
			me.pageTrailerList(keywords,page,15);
		},
		methods: {
			showTrailer(e){
				var me=this;
				var trailerid=e.currentTarget.dataset.trailerid;
				uni.navigateTo({
					url: '../movie/movie?trailerId='+trailerid,				
				});
				
			},
			pageTrailerList(keywords,page,pageSize){
				var me=this;
				var serverUrl=this.$serverUrl;
				
				uni.showLoading({
					mask:true,
					title:"请稍后..."
				});
				uni.showNavigationBarLoading()
				
				//查询猜你喜欢
				uni.request({			
					url: serverUrl+'/search/list?keywords='+keywords+'&page='+page+'&pageSize='+pageSize,
					method: 'GET',
					data: {},
					success: res => {
						// debugger
						// console.log(res.data)
						if (res.data.status == 200) {
							
							var tempList = res.data.data.rows;
							me.trailerList = me.trailerList.concat(tempList);
							me.totalPages=res.data.data.total;
							me.page=page;
						}
				
					},
					fail: () => {},
					complete: () => {
						uni.hideLoading();
						uni.hideNavigationBarLoading()
					}
				});
			},
			searchTrailer(e){
				var me=this;
				var value=e.detail.value;
				me.keywords-value;
				me.trailerList=[];
				
				me.pageTrailerList(value,1,15);
										
			}
		}
	}
</script>

<style lang="scss">
	.search-bar-block{	
		position: fixed;
		top: 90rpx;
		z-index: 10000;
		background-color: #FFFFFF;
		padding: 20rpx 0;
		.search-bar-wapper{
			display: flex;
			flex-direction: row;
			align-items: center;
			background-color: #eaeaea;
			margin: 0 20rpx;
			.search-icon{
				padding-left: 10rpx;
				width: 40rpx;
				height: 40rpx;
				
			}
			.search-input{		
				padding-left: 10rpx;
				font-size: 14px;
				background-color: #eaeaea;
				height: 60rpx;
				width: 650rpx;
			}
		}
		
		
	}
	
	.movie-list-block{
		padding: 110rpx 20rpx 0rpx 30rpx;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: start;
		.movie-wapper{	
			padding: 0 15rpx 15rpx 15rpx;
			.movie-image{
				width: 200rpx;
				height: 270rpx;
			}
			
		}
		
	}
</style>
